package javagamecontroller.activities.controllers;

import java.util.Map;
import util.input.android.events.AndroidButtonEvent;
import com.javagamecontroller.R;
import android.content.Context;
import android.os.Vibrator;


/**
 * A button manager for a gameboy controlelr
 * 
 * @author Ben Schwab
 * 
 */
public class GameBoyButtonManager extends ButtonManager {

    // I don't consider grid locations to be magic numbers. See the android
    // guide for more information.
    public GameBoyButtonManager (ControllerFrame c, Vibrator vibrator) {
        super(c, vibrator);
        setSelectButton(22);
    }

    @Override
    void initializeController () {
        Map<Integer, AndroidButton> buttonImageMap = getButtonImageMap();
        buttonImageMap.clear();
        Map<Integer, Integer> buttonIDMap = getButtonIdMap();
        buttonImageMap.clear();

        // create buttons
        AndroidButton bButton = new AndroidButton(R.drawable.gb_b, R.drawable.gb_b);
        AndroidButton aButton = new AndroidButton(R.drawable.gb_a, R.drawable.gb_a);
        AndroidButton upArrow = new AndroidButton(R.drawable.arrow_up_np, R.drawable.arrow_up);
        AndroidButton leftArrow =
                new AndroidButton(R.drawable.arrow_left_np, R.drawable.arrow_left);
        AndroidButton rightArrow =
                new AndroidButton(R.drawable.arrrow_right_np, R.drawable.arrow_right);
        AndroidButton downArrow =
                new AndroidButton(R.drawable.arrow_down_np, R.drawable.arrow_down);
        AndroidButton startButton =
                new AndroidButton(R.drawable.ps_button_start_np, R.drawable.ps_button_start);
        AndroidButton selectButton =
                new AndroidButton(R.drawable.ps_button_select_np, R.drawable.ps_button_select);

        // store buttons in map
        buttonImageMap.put(7, upArrow);
        buttonImageMap.put(12, leftArrow);
        buttonImageMap.put(14, rightArrow);
        buttonImageMap.put(19, downArrow);
        buttonImageMap.put(10, bButton);
        buttonImageMap.put(11, aButton);
        buttonImageMap.put(22, selectButton);
        buttonImageMap.put(23, startButton);

        // store button id's
        buttonIDMap.put(7, AndroidButtonEvent.GameBoy.UP);
        buttonIDMap.put(12, AndroidButtonEvent.GameBoy.LEFT);
        buttonIDMap.put(14, AndroidButtonEvent.GameBoy.RIGHT);
        buttonIDMap.put(19, AndroidButtonEvent.GameBoy.DOWN);
        buttonIDMap.put(10, AndroidButtonEvent.GameBoy.A);
        buttonIDMap.put(11, AndroidButtonEvent.GameBoy.B);
        buttonIDMap.put(22, AndroidButtonEvent.GameBoy.SELECT);
        buttonIDMap.put(23, AndroidButtonEvent.Playstation.START);

    }

}
